package com.apes.scm.masterdata.product.repository;

import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.scm.masterdata.product.model.ProductServiceHours;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import com.apes.scm.masterdata.product.model.ServeCategory;

import javax.xml.crypto.Data;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @BelongsProject: apes-server
 * @BelongsPackage: com.apes.scm.masterdata.product.repository
 * @ClassName: ProductServiceHoursRepository
 * @Author: pyb
 * @CreateTime: 2020-02-06 15:11
 * @Description:
 * @Version: 1.0
 */
public interface ProductServiceHoursRepository extends CustomRepository<ProductServiceHours, String> {
    public List<ProductServiceHours> findAllByCreateDateAfter(Date createDate);

    @Query("select t.id as id,t.product.id as productId,t.serviceHours as serviceHours,t.valid as valid,t.createDate as createDate,t.product.name as productName ," +
            " p.name as createor ,t.lastUpdatedStamp as lastUpdatedStamp ,e.code as stationTypeId,e.description as stationTypeName" +
            " from ProductServiceHours t " +
            " left join ServeCategory s on s.classify.id = t.product.classify.id and ROWNUM = 1 " +
            " left join Enumeration e on e.id = s.stationType.id " +
            " left join PartyRole r on r.id = t.creator " +
            " left join Party p on p.id = r.party.id" +
            " where t.lastUpdatedStamp>:lastUpdatedStamp " +
            " order by t.lastUpdatedStamp asc")
    public Page<Map> findAllByLastUpdatedStampAfter(Date lastUpdatedStamp, Pageable pageable);

    public List<ProductServiceHours> findAllByCreateDateBeforeAndLastUpdatedStampAfter(Date createDate,Date LastUpdatedStamp);
}
